﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin.Master" AutoEventWireup="true" CodeBehind="frm_Valoracion.aspx.cs" Inherits="ED_Nivelacion.PresentacionWeb.frm_Valoracion" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        .auto-style1 {
            width: 100px;
        }

        .auto-style2 {
            width: 49px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <form runat="server">
        <script>
            function show()
            {
                document.write("<head id='head2' runat='server'></head>");
            }
        </script>
        <script>
            //$(document).ready(function () {
            var ida = "";

            $(document).on("click", ".borrar", function () {

                var id = $(this).data("val");
                alert(id);
                $('#ContentPlaceHolder1_idEliminar').val(id);

            });


            $(document).on("click", ".editar", function () {

                var valor = $(this).data("valor");
                var actor = $(this).data("actor");
                var periodo = $(this).data("periodo");
                var id = $(this).data("id");

                //alert(id_v);


                $('#ContentPlaceHolder1_txt_Valor').val(valor);
                $('#ContentPlaceHolder1_cbm_Actor').val(actor);
                $('#ContentPlaceHolder1_Cbm_Periodo').val(periodo);
                $('#ContentPlaceHolder1_txt_Editar').val(id);
                //$("#ContentPlaceHolder1_cbm_Actor").attr('enabled', false);
                $('#ContentPlaceHolder1_btn_EditarV').show();
                $('#ContentPlaceHolder1_btm_Valorar').hide();
            });

            $(document).on("click", ".guardar", function () {
                $('#ContentPlaceHolder1_btn_EditarV').hide();
                $('#ContentPlaceHolder1_btm_Valorar').show();
            });
                    

            function limpiar() {
                $('#ContentPlaceHolder1_txt_Valor').val("");
                $('#ContentPlaceHolder1_cbm_Actor').val(0);
                $('#ContentPlaceHolder1_Cbm_Periodo').val(0);
            }

            function limpiar_asignar() {
                $('#ContentPlaceHolder1_txt_Item').val("");
                $('#ContentPlaceHolder1_txt_Requeridos').val("");
                $('#ContentPlaceHolder1_txt_Ponderacion').val("");
                $('#ContentPlaceHolder1_CbmCriterio').val(0);
            }

            $(document).on("click", ".asignar", function () {
                var idActor = $(this).data('actor');
                $('#ContentPlaceHolder1_txt_Captura').val(idActor);
                ED_Nivelacion.PresentacionWeb.ServiciosLocales.CuestionarioService.ObtenerDistribucionCriterioActor(idActor, correcto, error);
            });

            //function asignar(idActor)
            //{
            //var idActor = $(this).data('actor');
            //  alert(idActor);
            //$('#ContentPlaceHolder1_txt_Captura').val(idActor);
            //ED_Nivelacion.PresentacionWeb.ServiciosLocales.CuestionarioService.ObtenerDistribucionCriterioActor(idActor, correcto, error);
            //}

            function correcto(object)
            {
                var tabla2 = "";
                //alert(object.length);
                for (var i = 0; i < object.length; i++) {

                    var idist = object[i].idDsitribucion_Criterio;
                    var criterio = object[i].Criterio;
                    var items = object[i].Items;
                    var itemsn = object[i].Itens_Necesarios;
                    var ponderacion = object[i].Ponderacion;

                    var tabla = "<tr class='gradeA even'><td>" + idist + "</td><td>" + criterio + "</td><td>" + items + "</td><td>" + itemsn + "</td><td>" + ponderacion + "</td><td><a class='btn btn-danger btn-xs' onClick='eliminar(" + idist + ")'><span class='fa fa-trash-o'></span> Eliminar</a></td></tr>";
                    var tabla2 = tabla2.concat(tabla);
                }
                document.getElementById("peso").innerHTML = tabla2;
                $('#Ponderacionnnn').dataTable();
            }
            function error()
            {
                errorMessage("Error al generar tabla");
            }
                    
            function validar()
            {   <%ED_Nivelacion.Negocios.Periodo_C _obj = new ED_Nivelacion.Negocios.Periodo_C();%>
                var criterio = $('#ContentPlaceHolder1_CbmCriterio').val();
                var idActor = $('#ContentPlaceHolder1_txt_Captura').val();
                var periodo = <%=_obj.ObtenerPeriodo().Last().idPeriodo%>;
                if (criterio != "" && idActor != "" && periodo != "") {
                    var values = { idActor: idActor, idCriterio_Evaluacion: criterio, idPeriodo: periodo };
                    ED_Nivelacion.PresentacionWeb.ServiciosLocales.CuestionarioService.ValidarDistribucionCriterio(values, correctoV, errorV);    
                }
                else {
                    errorMessage("Seleccione todas las opciones.");
                }
                
            }

            function correctoV(data)
            {
                if (data == "OK") {
                    agregar();
                } else {
                    errorMessage("Ya fue asignado el criterio seleccionado");
                }
                            
            }
            function errorV()
            {
                errorMessage("Error");
            }

            function agregar()
            {<%ED_Nivelacion.Negocios.Periodo_C _objP = new ED_Nivelacion.Negocios.Periodo_C();%>
                var items = $('#ContentPlaceHolder1_txt_Item').val();
                var items_n = $('#ContentPlaceHolder1_txt_Requeridos').val();
                var ponderacion = $('#ContentPlaceHolder1_txt_Ponderacion').val();
                var actor = $('#ContentPlaceHolder1_txt_Captura').val();
                var criterio = $('#ContentPlaceHolder1_CbmCriterio').val();
                var periodo = <%=_objP.ObtenerPeriodo().Last().idPeriodo%>;

                var data = { Items: items, Itens_Necesarios: items_n, Ponderacion: ponderacion, idActor: actor, idCriterio_Evaluacion: criterio, idPeriodo: periodo }
                ED_Nivelacion.PresentacionWeb.ServiciosLocales.CuestionarioService.AgregarDCriterio(data, correctoA, errorA);
            }

            function correctoA()
            {
                sucessMessage("Ingresado Correctamente");
                var idActor = $('#ContentPlaceHolder1_txt_Captura').val();
                ED_Nivelacion.PresentacionWeb.ServiciosLocales.CuestionarioService.ObtenerDistribucionCriterioActor(idActor, correcto, error);

            }

            function mostrar() {
                var idActor = $('#ContentPlaceHolder1_txt_Captura').val();
                ED_Nivelacion.PresentacionWeb.ServiciosLocales.CuestionarioService.ObtenerDistribucionCriterioActor(idActor, correcto, error);

            }

            function errorA()
            {
                errorMessage("Error al ingresar");
            }

            function eliminar(id)
            {
                ED_Nivelacion.PresentacionWeb.ServiciosLocales.CuestionarioService.EliminarDCriterio(id, correctoE, errorE);
            }

            function correctoE() {
                sucessMessage("Eliminado Correctamente");
                mostrar();
            }

            function errorE()
            {
                errorMessage("No se pudo eliminar");
            }

        </script>

        <div class="col-lg-12">
            <asp:ScriptManager ID="ScriptManager1" runat="server">
                <Services>
                    <asp:ServiceReference Path="~/ServiciosLocales/CuestionarioService.asmx" />
                </Services>
            </asp:ScriptManager>
            <asp:Timer ID="Timer1" runat="server">
            </asp:Timer>

            <%
                ED_Nivelacion.Negocios.ValoracionActor_C _objValoracionA_C = new ED_Nivelacion.Negocios.ValoracionActor_C();
            %>

            <div class="portlet portlet-default">
                <div class="portlet-heading">
                    <div class="portlet-title">
                        <h4>TABLA DE VALORES</h4>

                    </div>
                    <div class="clearfix">
                        <div class="portlet-widgets">
                            <a class="btn btn-success btn-xs guardar" data-toggle="modal" data-target="#ValorarActor" onclick="limpiar()"><i class="fa fa-plus">Agregar </i></a>
                        </div>
                    </div>
                </div>
                <div class="portlet-body">
                    <div class="table-responsive">

                        <table id="example-table" class="table table-striped table-bordered table-hover table-green">
                            <thead>
                                <tr>
                                    <th class="auto-style2">#</th>
                                    <th>VALOR</th>
                                    <th>ACTOR</th>
                                    <th>PERIODO</th>
                                    <th>PONDERACIÓN</th>
                                    <th>ACCIÓN</th>
                                </tr>
                            </thead>

                            <tbody>
                                <%
                                    foreach (var item in _objValoracionA_C.ObtenerValoracionActor())
                                    {
                                %>

                                <tr class="odd gradeX">
                                    <td class="auto-style2"><%=item.idValoracion_Actores%></td>
                                    <td><%=item.Valor %></td>
                                    <td><%=item.Actor %></td>
                                    <td class="center"><%=item.Nombre_Periodo%></td>
                                    <td class="center"><a class="btn btn-green btn-sm asignar" data-toggle="modal" data-target="#AsignarPonderacion" data-actor="<%=item.idActor %>" onclick="asignar(<%=item.idActor %>)"><i class="icon-white fa fa-hand-o-right"></i>ASIGNAR</a></td>
                                    <td class="center"><a class="btn btn-orange btn-sm editar" data-toggle="modal" data-target="#ValorarActor" data-id="<%=item.idValoracion_Actores%>" data-valor="<%=item.Valor%>" data-actor="<%=item.idActor%>" data-periodo="<%=item.idPeriodo%>"><i class="fa fa-pencil"></i>MODIFICIAR</a></td>

                                </tr>

                                <%} %>
                            </tbody>
                            <asp:TextBox ID="idEliminar" runat="server" CssClass="hidden"></asp:TextBox>
                        </table>

                    </div>
                    <!-- /.table-responsive -->
                </div>
                <!-- /.portlet-body -->
            </div>
            <!-- /.portlet -->

        </div>

        <div class="col-lg-12">
            <div class="modal modal-flex fade" id="ValorarActor" tabindex="-1" role="dialog" aria-labelledby="flexModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="flexModalLabel">Agregar Valoración por Actor</h4>
                        </div>
                        <div id="Div1" class="modal-body" runat="server">

                            <div class="table-responsive">

                                <asp:TextBox ID="txt_Editar" runat="server" CssClass="hidden"></asp:TextBox>

                                <table id="Valor" class="table table-striped table-bordered table-hover table-blue">
                                    <thead>
                                        <tr>
                                            <th class="auto-style1">Datos</th>
                                            <th>Valorización</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td class="auto-style1">Valor:</td>
                                            <td>
                                                <asp:TextBox ID="txt_Valor" runat="server"></asp:TextBox>
                                                <ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" TargetControlID="txt_Valor" FilterType="Numbers" />
                                                <asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Usar un valor de 0 a 100" ControlToValidate="txt_Valor" Type="Integer" MinimumValue="1" MaximumValue="100"></asp:RangeValidator>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="auto-style1">Actor:</td>
                                            <td>
                                                <asp:DropDownList ID="cbm_Actor" runat="server" Enabled="true" AppendDataBoundItems="true">
                                                    <asp:ListItem Value="" Selected="True">Escoja una opción</asp:ListItem>
                                                </asp:DropDownList></td>
                                        </tr>


                                    </tbody>
                                </table>

                            </div>

                        </div>
                        <div class="modal-footer">
                            <asp:Button ID="btm_Valorar" runat="server" CssClass="btn btn-primary btn-sm" Text="GUARDAR" OnClick="btm_Valorar_Click" />
                            <asp:Button ID="btn_EditarV" runat="server" CssClass="btn btn-primary btn-sm" Text="EDITAR" OnClick="btn_EditarV_Click" />
                            <%--<asp:Button ID="" runat="server" cssclass="btn btn-primary btn-sm" Text="EDITAR" OnClick="btn_EditarV_Click"/>--%>
                        </div>
                    </div>
                    <!-- /.modal-content -->
                </div>
                <!-- /.modal-dialog -->
            </div>
            <!-- /.modal -->
        </div>

        <script>
            $(document).ready(function () {
                $('#Ponderacion').dataTable();
            });
        </script>

        <div class="col-lg-22">
            <div class="modal modal-flex fade in" id="AsignarPonderacion" tabindex="-1" role="dialog" aria-labelledby="flexModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="H1">Ponderación de Criterios</h4>
                        </div>
                        <div id="Div3" class="modal-body">
                            <div class="table-responsive">
                                <script>
                                    $(document).ready(function () {
                                        $('#Ponderacion').dataTable();
                                    });
                                </script>
                                <table id="Ponderacion" class="table table-striped table-bordered table-hover table-blue">
                                    <thead>
                                        <tr>
                                            <th>#</th>
                                            <th>Criterio de Evaluación:</th>
                                            <th>Items:</th>
                                            <th>Requeridos:</th>
                                            <th>Ponderación:</th>
                                            <th>Acción</th>
                                        </tr>
                                    </thead>
                                    <tbody id="peso">
                                    </tbody>


                                </table>
                            </div>
                            <!-- /.table-responsive -->




                            <div class="modal-footer">
                                <asp:TextBox ID="txt_Captura" runat="server" CssClass="hidden"></asp:TextBox>
                                <table id="Table1" class="table table-bordered table-hover table-blue" border="0">
                                    <thead>
                                    </thead>
                                    <tbody id="Tbody1">
                                        <tr>
                                            <td class="auto-style3">Criterio de Evaluación</td>
                                            <td>
                                                <asp:DropDownList CssClass="form-control" ID="CbmCriterio" Enabled="true" runat="server" AppendDataBoundItems="true" Style="width: 200px;">
                                                    <asp:ListItem Value="" Selected="True">Escoja una opción</asp:ListItem>
                                                </asp:DropDownList></td>
                                            <td></td>
                                        </tr>
                                        <tr>
                                            <td class="auto-style3">Items:</td>
                                            <td>
                                                <asp:TextBox ID="txt_Item" runat="server"></asp:TextBox></td>
                                            <ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender2" runat="server" TargetControlID="txt_Item" FilterType="Numbers" />
                                            <td></td>
                                        </tr>
                                        <tr>
                                            <td class="auto-style3">Requeridos:</td>
                                            <td>
                                                <asp:TextBox ID="txt_Requeridos" runat="server"></asp:TextBox></td>
                                            <ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender3" runat="server" TargetControlID="txt_Requeridos" FilterType="Numbers" />
                                            <td>
                                                <asp:CompareValidator ID="CompareItems" runat="server" ErrorMessage="Debe ser menor o igual que Items" ControlToValidate="txt_Requeridos" ControlToCompare="txt_Item" Operator="LessThanEqual" Type="Integer"></asp:CompareValidator></td>
                                        </tr>
                                        <tr>
                                            <td class="auto-style3">Ponderación:</td>
                                            <td>
                                                <asp:TextBox ID="txt_Ponderacion" runat="server"></asp:TextBox></td>
                                            <ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender4" runat="server" TargetControlID="txt_Ponderacion" FilterType="Numbers" />
                                            <td>
                                                <asp:RangeValidator ID="RangeValidator2" runat="server" ErrorMessage="Usar un valor de 0 a 100" ControlToValidate="txt_Ponderacion" Type="Integer" MinimumValue="1" MaximumValue="100"></asp:RangeValidator>
                                            </td>
                                        </tr>
                                    </tbody>

                                </table>

                                <a id="btm_Valor" class=" btn btn-primary" onclick="validar()">GUARDAR</a>
                                <div class="clearfix"></div>
                            </div>


                        </div>


                    </div>
                    <!-- /.modal-content -->
                </div>

            </div>
        </div>
        <!-- /.modal-dialog -->


        <script>
            $('[data-val]').click(function () {
                var Id = $(this).data('val');
                $("#ContentPlaceHolder1_idEliminar").val(Id);
                alert(Id);
            });

            $('[data-toggle="confirmation"]').confirmation({
                placement: 'top', // How to position the confirmation - top | bottom | left | right
                trigger: 'click', // How confirmation is triggered - click | hover | focus | manual
                title: 'Esta seguro?', // Default title value if `data-title` attribute isn't present  
                template: '<div class="popover" >' +
                    '<div class="arrow"></div>' +
                    '<h3 class="popover-title"></h3>' +
                    '<div class="popover-content text-center">' +
                    '<div id="botones" class="btn-group">' +
                    '<a class="btn btn-xs" data-dismiss="confirmation"></a>' +
                    '</div>' +
                    '</div>'
                , btnOkClass: 'btn-primary'
                , btnOkIcon: 'fa fa-check-circle'
                , btnCancelClass: 'btn-danger'
                , btnOkLabel: 'Si'
                , btnCancelIcon: 'fa fa-times-circle'
                , btnCancelLabel: 'No',
                singleton: true, // Set true to allow only one confirmation to show at a time.
                popout: false, // Set true to hide the confirmation when user clicks outside of it.
                onConfirm: function () {

                }, // Set event when click at confirm button
                onCancel: function () { }
            }); // Set event when click at cancel button

            $(document).ready(function () {
                $("#<%Response.Write(CbmCriterio.ClientID);%>").searchable(
                                                         {
                                                             maxListSize: 400,                       // if list size are less than maxListSize, show them all
                                                             maxMultiMatch: 10,                      // how many matching entries should be displayed
                                                             exactMatch: false,                      // Exact matching on search
                                                             wildcards: true,                        // Support for wildcard characters (*, ?)
                                                             ignoreCase: true,                       // Ignore case sensitivity
                                                             latency: 200,                           // how many millis to wait until starting search
                                                             warnMultiMatch: 'top {0} matches ...',  // string to append to a list of entries cut short by maxMultiMatch
                                                             warnNoMatch: 'No existen coincidencias',          // string to show in the list when no entries match
                                                             zIndex: 'auto'                          // zIndex for elements generated by this plugin
                                                         });

        </script>
    </form>
</asp:Content>
